<?php

namespace App\Http\Controllers;

use App\Http\Requests\User\LoginForm;
use Illuminate\Support\Facades\Auth;
use App\Models\User;

class SignController extends Controller
{
    public function index(){
        if (Auth::check()) {
            return redirect()->route('index');
        }
        return view('login');
    }

    public function store(LoginForm $request){
        if (Auth::attempt(['email' => $request->email, 'password' => $request->password],$request->has('remember'))) {
            return redirect()->route('index');
        }else{
            session()->flash('danger','用户名或密码不对');
            return redirect()->back();
        }
    }

    public function logout(){
        if(Auth::logout()){
            return redirect()->route('login');
        }
        return redirect()->route('index');
    }
}
